/*
 * File: HangmanLexicon.java
 * -------------------------
 * This file contains the implementation for part III of 
 * the assignment: HangmanLexicon. Words are loaded from a dictionary file
 * and loaded into an ArrayList
 */


import java.io.*;
import java.util.*;
import acm.util.*;

public class HangmanLexicon {

	private static final String DICT_FILE = "HangmanLexicon.txt";
	/**
	 * Words will be stored here
	 */
	private ArrayList<String> words;
	
	public HangmanLexicon(){
		loadDictionaryWords();
	}
	
	/**
	 * Loads a list of dictionary words into memory
	 */
	private void loadDictionaryWords(){
		words = new ArrayList<String>();
				
		try{
			BufferedReader dictionaryWords = new BufferedReader(new FileReader(DICT_FILE));
			while(true) {
				String word = dictionaryWords.readLine();
				//EOF
				if (word==null){
					break;
				}
				words.add(word);
			}
			dictionaryWords.close();
		}
		catch(IOException ex){
			
			throw new ErrorException(ex);
		}
	}
	
/** Returns the number of words in the lexicon. */
	public int getWordCount() {
		if (words==null){
			return 0;
		}
		
		return words.size();
	}

/** Returns the word at the specified index. */
	public String getWord(int index) {
		if (words==null){
			return "";
		}
		
		return words.get(index);
	};
}
